package com.wn.consumer.controller;

import com.wn.consumer.feign.UserFeignClient;
import com.wn.domain.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.tags.Tags;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author yellow Docter
 * @date 2022 -10-25
 * @desc
 */
@RestController
@RequestMapping("feign")
@Api(tags = "user的消费者")        //  类的说明
public class UserConsumerController {

    @Autowired
    private UserFeignClient userFeignClient;

    @ApiOperation("通过id查询")       //方法的说明
    @GetMapping("user/{id}")
    public User findUser(@PathVariable Integer id){
        //远程调用 restTempldate
        // openFeign 远程调用
        User user = userFeignClient.findUser(id);
        return user;
    }

    @ApiOperation("添加user的操作")
    @PostMapping
    public String saveUser(@RequestBody User user){
        String s = userFeignClient.saveUser(user);
        return s;
    }

    @DeleteMapping("{id}")
    public String removeUser(@PathVariable("id") Integer id){
        // openfeign的远程调用
        String s = userFeignClient.removeUser(id);
        return s;
    }

}
